package com.v.partitionerAndwritable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;


//将mapper阶段传出的<K,V>中的V进行分区处理！！！
public class partitionerandwritable extends Partitioner<FlowBean, Text> {
    @Override
    public int getPartition(FlowBean flowBean, Text text, int numPartitions) {

        //将hadoop的text类转换成java的字符串类
        String phone = text.toString();

        //这里取字串，左闭右开
        String subphone = phone.substring(0, 3);

        //创建partition分区变量
        int partition;

        //写分区逻辑代码
        if("136".equals(subphone)){
            partition = 0;
        } else if("137".equals(subphone)){
            partition = 1;
        } else if("138".equals(subphone)){
            partition = 2;
        } else if("139".equals(subphone)){
            partition = 3;
        } else {
            partition = 4;
        }

        return partition;
    }
}
